home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 41 / Issue 41.iso / pc / PCSoftware / Netscape 6 Official Release / nim.xpi / bin / chrome / aim.jar / content / aim / contextMenu.js < prev    next >
Encoding:
JavaScript  |  2000-09-07  |  7.1 KB  |  223 lines

  1. /*------------------------------ nsContextMenu ---------------------------------
  2. |   This JavaScript "class" is used to implement the IM standalon's            |
  3. |   content-area context menu.                                                 |
  4. |                                                                              |
  5. |   For usage, see references to this class in contextMenu.xul.                |
  6. |                                                                              |
  7. ------------------------------------------------------------------------------*/
  8. // global context menu
  9. //var contextMenu = null;
  10.  
  11. function nsContextMenu( xulMenu ) {
  12.   this.menu                  = null;
  13.     this.onlineTab        = false;
  14.     this.listSetupTab     = false;
  15.   this.sidebar          = false;
  16.   this.screenName       = "";
  17.   this.target           = null;
  18.  
  19.   // Initialize new menu.
  20.   this.initMenu( xulMenu );
  21. }
  22.  
  23. // Prototype for nsContextMenu "class."
  24. nsContextMenu.prototype = {
  25.  
  26.     // onDestroy is a no-op at this point.
  27.     onDestroy : function () {
  28.     },
  29.  
  30.     // Initialize context menu.
  31.     initMenu : function ( popup, event ) {
  32.         
  33.         this.menu = popup;
  34.  
  35.         // Get contextual info.
  36.         this.setTarget( document.popupNode );
  37.     
  38.         // Initialize (disable/remove) menu items.
  39.         this.initItems();
  40.     },
  41.  
  42.     initItems : function () {
  43.         this.initOnlineItems();
  44.         this.initListSetupItems();
  45.     },
  46.  
  47.     initOnlineItems : function () {
  48.         this.showItem( "context-sendIM", this.onlineTab );
  49.         this.showItem( "context-sendChat", this.onlineTab );
  50.         //this.showItem( "context-EditList", this.sidebar );
  51.     },
  52.  
  53.     initListSetupItems : function () {
  54.         this.showItem( "context-addBuddy", this.listSetupTab );
  55.         this.showItem( "context-addGroup", this.listSetupTab );
  56.         this.showItem( "context-delete", this.listSetupTab );
  57.         //this.showItem( "context-editAB", this.listSetupTab );
  58.     },
  59.  
  60.     // Set various context menu attributes based on the state of the world.
  61.     setTarget : function ( node ) {
  62.         // Remember the node that was clicked.
  63.         this.target = node;
  64.               var sidebarframe=window; 
  65.           // determine if we're in the standalone or sidebar
  66.         var parentState = top.document.getElementById("AimSidebarState");
  67.         if(!parentState)
  68.         {
  69.             var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  70.             if (tab.getAttribute('index') == 0 )  
  71.                 {
  72.                 this.sidebar = true;   
  73.                 this.onlineTab = true;
  74.                 this.listSetupTab = false;
  75.                 }        
  76.                        else
  77.                 {
  78.                 this.sidebar = true;   
  79.                                 this.onlineTab = false;
  80.                                 this.listSetupTab = true;  
  81.                 }
  82.         }
  83.         else
  84.         {
  85.               var curTab;
  86.               curTab = parentState.getAttribute("AimSidebarTab");
  87.           // Determine if we're in the Online tab or List Setup tab
  88.               if(curTab == "Online")
  89.                   {
  90.                       this.onlineTab = true;
  91.                       this.listSetupTab  = false;
  92.               this.sidebar = false;
  93.                   }
  94.               else
  95.                   {
  96.                       this.listSetupTab = true;
  97.                       this.onlineTab = false;
  98.               this.sidebar = false;
  99.                   }
  100.           }
  101.  
  102.         // set the screen name based on the target
  103.         this.screenName = this.target.parentNode.parentNode.getAttribute('ScreenName');
  104.         //dump("Context: Screen name is " + this.screenName + "\n");
  105.     },
  106.  
  107.     // sendIM
  108.     cmdContextSendIM : function () {
  109.       dump("Context: Send IM\n");
  110.  
  111.       if (aimIMDoesIMExist(this.screenName))
  112.               aimErrorBox(aimString("msg.DuplicateIM"));
  113.           else 
  114.                 aimIMInvokeIMForm(this.screenName, null);
  115.  
  116.     },
  117.  
  118.     // sendChat
  119.     cmdContextSendChat : function () {
  120.           //window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no','', false,'outgoingchat');
  121.      inviteArgsObj = {
  122.          inviteProposalScreenName: '', 
  123.          inviteProposalObj: null,
  124.          invitedScreenNames: getSelectedBuddiesFromList(),
  125.          inviteToExistingWindow: false,
  126.          inviteMode: 'outgoingchat'
  127.          }
  128.           window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  129.  
  130.  
  131.           dump("Context: Chat\n");
  132.     },
  133.  
  134.     // Edit List
  135.     cmdContextEditList : function  () {
  136.       dump("Context: Edit List\n");
  137.       //toOpenWindowByType2('Aim:AimApp', 'chrome://aim/content/App.xul');
  138.     },
  139.  
  140.     // addbuddy
  141.     cmdContextAddBuddy : function () {
  142.       dump("Context: Add Buddy\n");
  143.       cmdAddBuddy();
  144.     },
  145.  
  146.     // addGroup
  147.     cmdContextAddGroup : function () {
  148.       dump("Context: Add Group\n");
  149.       cmdAddGroup();
  150.     },
  151.  
  152.       // delete
  153.     cmdContextDelete : function () {
  154.       dump("Context: Delete\n");
  155.       cmdDelete();
  156.     },
  157.  
  158.     //cmdContextEditAB : function () {
  159.       //dump("Context: Edit AddressBook\n");
  160.       //cmdAbEditCard();
  161.     //},     
  162.  
  163.     // Utilities
  164.  
  165.     // Show/hide one item (specified via name or the item element itself).
  166.     showItem : function ( itemOrId, show ) {
  167.         var item = null;
  168.         if ( itemOrId.constructor == String ) {
  169.             // Argument specifies item id.
  170.             item = document.getElementById( itemOrId );
  171.         } else {
  172.             // Argument is the item itself.
  173.             item = itemOrId;
  174.         }
  175.         if ( item ) {
  176.             var styleIn = item.getAttribute( "style" );
  177.             var styleOut = styleIn;
  178.             if ( show ) {
  179.                 // Remove style="display:none;".
  180.                 styleOut = styleOut.replace( "display:none;", "" );
  181.  
  182.             } else {
  183.                 // Set style="display:none;".
  184.                 if ( styleOut.indexOf( "display:none;" ) == -1 ) {
  185.                     // Add style the first time we need to.
  186.                     styleOut += "display:none;";
  187.                 }
  188.             }
  189.             // Only set style if it's different.
  190.             if ( styleIn != styleOut ) {
  191.                 item.setAttribute( "style", styleOut );
  192.             }
  193.         }
  194.     },
  195.  
  196.     // Set given attribute of specified context-menu item.  If the
  197.     // value is null, then it removes the attribute (which works
  198.     // nicely for the disabled attribute).
  199.     setItemAttr : function ( id, attr, val ) {
  200.         var elem = document.getElementById( id );
  201.         if ( elem ) {
  202.             if ( val == null ) {
  203.                 // null indicates attr should be removed.
  204.                 elem.removeAttribute( attr );
  205.             } else {
  206.                 // Set attr=val.
  207.                 elem.setAttribute( attr, val );
  208.             }
  209.         }
  210.     },
  211.  
  212.     // Set context menu attribute according to like attribute of another node
  213.     // (such as a broadcaster).
  214.     setItemAttrFromNode : function ( item_id, attr, other_id ) {
  215.         var elem = document.getElementById( other_id );
  216.         if ( elem && elem.getAttribute( attr ) == "true" ) {
  217.             this.setItemAttr( item_id, attr, "true" );
  218.         } else {
  219.             this.setItemAttr( item_id, attr, null );
  220.         }
  221.     }
  222. };
  223.